# ============================================================
# * Copyright © hk. 2022-2025. All rights reserved.
# * File name: CMakeLists.txt
# * Author   : 苏木
# * Date     : 2025-05-22
# * Version  : 
# * Description: cmake version 3.16.3
# ============================================================
## https://cmake.com.cn/cmake/help/latest/guide/tutorial/index.html
## https://cmake.org/cmake/help/latest/

# 指定 CMake 的最低版本要求
# --------------------------------------------------
cmake_minimum_required(VERSION 3.10)


# 设置项目名称和使用的编程语言
# --------------------------------------------------
project(SPROJECT C)


# 指定可执行程序和源文件
# --------------------------------------------------
add_executable(app_demo.out main.c)


# 字符串处理
# --------------------------------------------------

# 1. 查找
# string(FIND inputString subString outVar [REVERSE])
message(STATUS "==> 字符串查找")
set(longStr abcdefabcdef)
set(shortBit def)
string(FIND ${longStr} ${shortBit} fwdIndex)
string(FIND ${longStr} ${shortBit} revIndex REVERSE)
message(STATUS "fwdIndex = ${fwdIndex}, revIndex = ${revIndex}")
message("")

# 2. 替换
# string(REPLACE matchString replaceWith outVar input [input...])
# string(REGEX MATCH regex outVar input [input...])
# string(REGEX MATCHALL regex outVar input [input...])
# string(REGEX REPLACE regex replaceWith outVar input [input...])
message(STATUS "==> 字符串替换")
set(longStr abcdefabcdef)
string(REGEX MATCHALL "[ace]" matchVar ${longStr})
string(REGEX REPLACE "([de])" "X\\1Y" replVar ${longStr})
message(STATUS "matchVar = ${matchVar}")
message(STATUS "replVar = ${replVar}")
message("")

# 3. 提取
# string(SUBSTRING input index length outVar)
message(STATUS "==> 字符串提取")
set(longStr abcdefabcdef)
string(SUBSTRING ${longStr} 1 5 result)  # 从第1个字符开始截取5个字符
message(STATUS "result = ${result}")     # 输出: bcdef
message("")

# 4. 计算长度
# string(LENGTH input outVar)
message(STATUS "==> 字符串长度计算")
set(longStr abcdefabcdef)
string(LENGTH ${longStr} strLen)  # 从第1个字符开始截取5个字符
message(STATUS "strLen = ${strLen}")     # 输出: bcdef
message("")

# 5. 转换大小写
# string(TOLOWER input outVar)
# string(TOUPPER input outVar)
message(STATUS "==> 字符串大小写转换")
set(longStr abcDEFABCdef)
string(TOLOWER ${longStr} tolowerVar)    # 转小写
string(TOUPPER ${longStr} toupperVar)    # 转大写
message(STATUS "tolowerVar = ${tolowerVar}")
message(STATUS "toupperVar = ${toupperVar}")
message("")

# 6. 去掉开头结尾空格
# string(STRIP input outVar)
message(STATUS "==> 字符串开头结尾空格")
set(longStr " abcDEFABCdef  ")
message(STATUS "longStr = ${longStr}")
string(STRIP ${longStr} resultVar)    # 转小写
message(STATUS "resultVar = ${resultVar}")
message("")
